package com.hdoit.ares.web.wxPayActive.controllers;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.tennetcn.common.utils.RandomUtils;
import com.tennetcn.component.web.BaseController;
import com.tennetcn.web.cbase.wechat.WechatPayService;

@Controller
@RequestMapping(value = "/admin/wxPayActive/wxRedEnvelopes/")
public class WxRedEnvelopesController extends BaseController {
	@Override
	public String getRoutePath() {
		return "areas/admin/wxPayActive/wxRedEnvelopes/";
	}

	private WechatPayService wechatPayService;

	public WechatPayService getWechatPayService() {
		return wechatPayService;
	}

	@Resource
	public void setWechatPayService(WechatPayService wechatPayService) {
		this.wechatPayService = wechatPayService;
	}
	

	private final String ordinaryViewName = "ordinary";
	private final String fissionViewName = "fission";
	
	@ResponseBody
	@RequestMapping(value = ordinaryViewName, method = { RequestMethod.GET,
			RequestMethod.POST })
	public void index(Model model) {
		WxPaySendRedpackRequest request = new WxPaySendRedpackRequest();
		
		request.setSendName("普天永利");
		request.setNonceStr("" + System.currentTimeMillis()+ RandomUtils.randomInt(1000, 9999));
		request.setMchBillNo("ptyl" + System.currentTimeMillis()+ RandomUtils.randomInt(1000, 9999));
		request.setReOpenid("oTZhz1V3VzD090pSoCaleWDBSKsc");
		request.setTotalAmount(100);
		request.setTotalNum(1);
		request.setWishing("测试发红包接口");
		request.setClientIp("192.168.200.118");
		request.setActName("红包雨");
		
		try {
			wechatPayService.sendRedpack(request);
		} catch (WxPayException e) {
			e.printStackTrace();
		}
	}

	
	
	@ResponseBody
	@RequestMapping(value = fissionViewName, method = { RequestMethod.GET,
			RequestMethod.POST })
	public void fission(Model model) {
		WxPaySendRedpackRequest request = new WxPaySendRedpackRequest();
		
		request.setSendName("普天永利");
		request.setNonceStr("" + System.currentTimeMillis()+ RandomUtils.randomInt(1000, 9999));
		request.setMchBillNo("ptyl" + System.currentTimeMillis()+ RandomUtils.randomInt(1000, 9999));
		request.setReOpenid("oTZhz1V3VzD090pSoCaleWDBSKsc");
		request.setTotalAmount(500);
		request.setAmtType("ALL_RAND");
		request.setTotalNum(5);
		request.setRemark("分享红包有机会再中红包");
		request.setWishing("测试发红包接口");
		request.setClientIp("192.168.200.118");
		request.setActName("红包雨");
		
		try {
			wechatPayService.sendRedpack(request);
		} catch (WxPayException e) {
			e.printStackTrace();
		}
	}
}
